/**
 * 
 * @param attr 指令名称
 * @returns 格式化后的指令名称
 * v-on:click.stop -> on
 */
export function parseDirectiveName(attr: string) {
    let name = attr.split(".").shift();
    if (name) {
        name = name.split(":").shift();
        if (name) {
            name = name.replace('v-', '');
        }
    }
    return name;
}

/**
 * 
 * v-on:click.stop -> click
 */
export function parseDirectiveArg(attr: string) {
  let argMatch = attr.match(/((?<=:)(\w+(?=[\.])))|(?<=:)\w+/g);
  let arg: string | undefined;
  if (argMatch) {
    arg = argMatch[0];
  }
  return arg;
}

/**
 * 
 * v-on:click.stop -> stop
 */
export function parseDirectiveModifiers(attr: string) {
  let modifiers: Record<string, boolean> = {};
  let modifier = attr.match(/(?<=\.)\w+/g);
  if (modifier) {
    modifier.forEach((item) => {
      modifiers[item] = true;
    });
  }
  return modifiers;
}
